package com.example.xsssglxt.controller;

import com.example.xsssglxt.entity.Admin;
import com.example.xsssglxt.entity.DomiteryManage;
import com.example.xsssglxt.entity.Louyu;
import com.example.xsssglxt.entity.Student;
import com.example.xsssglxt.mapper.AdminMapper;
import com.example.xsssglxt.mapper.DomiteryManageMapper;
import com.example.xsssglxt.mapper.StudentMapper;
import com.example.xsssglxt.mapper.SushemanagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sushe")
public class AdminController {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private SushemanagerMapper sushemanagerMapper;

    @Autowired
    private DomiteryManageMapper domiteryManageMapper;
    @Autowired
    private StudentMapper studentMapper;

//    public Map<String,Object> xl(){
//        List<Admin> data3=adminMapper.selectadd1();
//        System.out.println(data3);
//        Map<String,Object> res=new HashMap<>();
//        res.put("data",data3);
//        return res;
//    }
    @GetMapping("/lb")
    public Map<String,Object> index2() {


        List<Admin> data= adminMapper.selectadd1();

        Map<String, Object> res = new HashMap<>();
        res.put("data",data);


        return  res;
    }
    @GetMapping("/login")
    public Map<String,Object> index(@RequestParam String name,@RequestParam String password ,@RequestParam Integer type){
Map<String,Object> res=new HashMap<>();

        if(type == 0){
            List<Admin> data=adminMapper.selectadd(name,password);
            if(data.isEmpty()){
                res.put("msg","用户不存在");
                res.put("code",500);
            }else{
                res.put("code",200);
                res.put("data",data);
                res.put("msg","登录成功");
            }
        }else if(type == 1){
            List<Admin> data1=adminMapper.selectadd1(name,password);
            if(data1.isEmpty()){
                res.put("msg","用户不存在");
                res.put("code",500);
            }else{
                res.put("code",200);
                res.put("data",data1);
                res.put("msg","登录成功");
            }
        }else if(type == 2){
List<Admin> data2=adminMapper.selectadd2(name,password);
            if(data2.isEmpty()){
                res.put("msg","用户不存在");
                res.put("code",500);
            }else{
                res.put("code",200);
                res.put("data",data2);
                res.put("msg","登录成功");
            }
        }
        return  res;

    }
}
